import requests
from bs4 import BeautifulSoup


class tryTodo():

    def axiba(self,url):

        self.url = url

        self.menu = {}


        res = requests.get(self.url)

        html = res.text

        bs = BeautifulSoup(html,'html.parser')

        classDiv = bs.find_all(class_="info pure-u")

        for item in classDiv:

            a = item.find('a')

            p = item.find(class_="ing ellipsis")


            self.menu[a.text[17:-13]] = '\n 链接为：'+self.url+a['href']+'\n 需要用到的食材：'+p.text


            # print('菜名为：'+str(a.text)+"\t"+'链接为：'+str(a['href']))
            #
            #
            # print('需要用到的材料：'+str(p.text))

        for k,v in self.menu.items():

            print(k,v)

a = tryTodo()

a.axiba('http://www.xiachufang.com/explore')